(function(){BX.namespace("BX.Rest.Configuration.Install");if(!BX.Rest.Configuration.Install){return}function t(){}t.prototype={init:function(t){this.id=t.id;this.importByProcessId=t.importByProcessId;this.signedParameters=t.signedParameters;this.from=t.from;this.next="";this.section=[];this.progressDescriptionContainer=BX.findChildByClassName(BX(this.id),"rest-configuration-info");this.needClearFull=t.needClearFull;this.needClearFullConfirm=t.needClearFullConfirm;this.skipClearing=t.skipClearing;this.errors=[];this.loaderPointSymbol=".";this.loaderPointCount=3;this.closeSliderPopup=false;this.showCloseConfirmation=true;var e=BX.findChildByClassName(BX(this.id),"start_btn");if(e!==null){BX.bind(e,"click",BX.delegate((function(){if(this.needClearFullConfirm===true){this.showConfirmClearAll(e)}else if(this.importByProcessId===true){this.run()}else{this.start()}}),this))}else{if(this.importByProcessId===true){this.run()}else{this.start()}}var i=BX.findChildByClassName(BX(this.id),"start_later_btn");if(i!==null){BX.bind(i,"click",BX.delegate((function(){this.showPopupInstallLater(i)}),this))}var s=BX.SidePanel.Instance.getTopSlider();if(s){BX.addCustomEvent(s,"SidePanel.Slider:onClose",this.handleSliderClose.bind(this))}},handleSliderClose:function(t){if(this.showCloseConfirmation){t.denyAction()}if(!this.closeSliderPopup){this.closeSliderPopup=new top.BX.PopupWindow({titleBar:BX.message("REST_CONFIGURATION_IMPORT_HOLD_CLOSE_POPUP_TITLE"),content:BX.message("REST_CONFIGURATION_IMPORT_HOLD_CLOSE_POPUP_DESCRIPTION"),closeIcon:false,buttons:[new top.BX.PopupWindowButton({text:BX.message("REST_CONFIGURATION_IMPORT_HOLD_CLOSE_POPUP_BTN_CONTINUE"),className:"popup-window-button-accept",events:{click:function(){this.closeSliderPopup.close()}.bind(this)}}),new top.BX.PopupWindowButton({className:"popup-window-button popup-window-button-link",text:BX.message("REST_CONFIGURATION_IMPORT_HOLD_CLOSE_POPUP_BTN_CLOSE"),events:{click:function(){this.showCloseConfirmation=false;t.slider.close();this.closeSliderPopup.close()}.bind(this)}})]})}if(this.showCloseConfirmation){this.closeSliderPopup.show()}},showPopupInstallLater:function(t){this.sendAjax("preInstallOff",{},BX.delegate((function(e){BX.UI.Dialogs.MessageBox.show({message:BX.create("p",{html:BX.message("REST_CONFIGURATION_IMPORT_PRE_INSTALL_LATER_APP_POPUP_DESCRIPTION")}),modal:true,bindElement:t,buttons:[new BX.UI.Button({text:BX.message("REST_CONFIGURATION_IMPORT_INSTALL_LATER_POPUP_CLOSE_BTN"),color:BX.UI.Button.Color.PRIMARY,onclick:function(t){t.context.close();BX.SidePanel.Instance.close()}})]})}),this))},showConfirmClearAll:function(t){var e=new BX.UI.Button({color:BX.UI.Button.Color.PRIMARY,state:BX.UI.Button.State.DISABLED,text:BX.message("REST_CONFIGURATION_IMPORT_INSTALL_CONFIRM_POPUP_BTN_CONTINUE"),onclick:BX.delegate((function(t){if(!BX("CONFIGURATION_ACCEPT_CLEAR_ALL").checked){return false}t.context.close();this.start()}),this)});var i=BX.create("div",{children:[BX.create("p",{text:BX.message("REST_CONFIGURATION_IMPORT_INSTALL_CONFIRM_POPUP_TEXT")}),BX.create("INPUT",{attrs:{id:"CONFIGURATION_ACCEPT_CLEAR_ALL",type:"checkbox",name:"ACCEPT_CLEAR_ALL",value:"Y"},events:{change:function(t){e.setState(this.checked?BX.UI.Button.State.ACTIVE:BX.UI.Button.State.DISABLED)}}}),BX.create("label",{attrs:{for:"CONFIGURATION_ACCEPT_CLEAR_ALL"},text:BX.message("REST_CONFIGURATION_IMPORT_INSTALL_CONFIRM_POPUP_CHECKBOX_LABEL")})]});BX.UI.Dialogs.MessageBox.show({message:i,modal:true,bindElement:t,buttons:[e,new BX.UI.Button({text:BX.message("REST_CONFIGURATION_IMPORT_INSTALL_CONFIRM_POPUP_BTN_CANCEL"),onclick:function(t){t.context.close()}})]})},setDescription:function(t,e){t="REST_CONFIGURATION_IMPORT_INSTALL_STEP_"+t;var i=BX.message[t]?BX.message(t):BX.message("REST_CONFIGURATION_IMPORT_INSTALL_STEP_MSGVER_1");if(this.loaderPointCount>0&&BX.type.isInteger(e)){var s="&nbsp;";var n=e%this.loaderPointCount+1;var a=this.loaderPointCount-n;i+=this.loaderPointSymbol.repeat(n)+s.repeat(a)}BX.html(this.progressDescriptionContainer,i)},showLoader:function(){BX.addClass(BX.findChildByClassName(BX(this.id),"rest-configuration-start-icon-main"),"rest-configuration-start-icon-main-loading");BX.style(BX.findChildByClassName(BX(this.id),"start-btn-block"),"display","none");this.setDescription("")},showFinish:function(t){var e=BX.findChildByClassName(BX(this.id),"rest-configuration-start-icon-main");BX.removeClass(e,"rest-configuration-start-icon-main-loading");var i="";if(this.errors.length===0){i=BX.message("REST_CONFIGURATION_IMPORT_FINISH_DESCRIPTION_MSGVER_1");BX.addClass(e,"rest-configuration-start-icon-main-success")}else{i=BX.message("REST_CONFIGURATION_IMPORT_FINISH_ERROR_DESCRIPTION");BX.addClass(e,"rest-configuration-start-icon-main-error")}BX.cleanNode(this.progressDescriptionContainer);this.progressDescriptionContainer.appendChild(BX.create("p",{attrs:{className:""},text:i}));if(this.errors.length!==0){this.progressDescriptionContainer.appendChild(BX.create("div",{attrs:{className:"rest-configuration-links"},children:[BX.create("a",{attrs:{"data-slider-ignore-autobinding":"true",href:""},events:{click:BX.delegate(this.openPopupErrors,this)},text:BX.message("REST_CONFIGURATION_IMPORT_ERRORS_REPORT_BTN")})]}))}BX.insertAfter(BX.create("div",{attrs:{className:"rest-configuration-action-block"},children:[]}),BX.findChildByClassName(BX(this.id),"rest-configuration-start-icon-main"));if(this.errors.length===0){BX(this.id).appendChild(BX.create("p",{attrs:{className:"rest-configuration-import-finish rest-configuration-info"},html:BX.message("REST_CONFIGURATION_IMPORT_INSTALL_FINISH_TEXT")}))}var s=[];if(!!t.createItemList&&t.createItemList.length>0){for(var n=0;n<t.createItemList.length;n++){if(!t.createItemList[n]["DATA"]){t.createItemList[n]["DATA"]={events:{}}}var a=t.createItemList[n]["TAG"];var o=t.createItemList[n]["DATA"];if(!o["events"]){o["events"]={}}if(!o["events"]["click"]){o["events"]["click"]=function(t){if(t.target.localName==="a"&&t.target.href.indexOf(t.target.baseURI)===0){t.preventDefault();BX.remove(t.target)}}}s[n]=BX.create(a,o);this.progressDescriptionContainer.appendChild(s[n])}}top.BX.Event.EventEmitter.emit("BX.Rest.Configuration.Install:onFinish",new top.BX.Event.BaseEvent({data:{finishResponse:t,errors:this.errors,elementList:s,from:this.from}}));this.showCloseConfirmation=false},finish:function(){var t=this;this.sendAjax("finish",{},BX.delegate((function(t){if(t.data.result===true){this.showFinish(t.data)}else{this.finish()}}),this))},addErrors:function(t){for(var e=0;e<t.length;e++){this.errors.push(t[e])}},openPopupErrors:function(){var t="";this.errors.forEach((function(e){if(BX.Type.isString(e)){t+=e+"\r\n"}else{if("message"in e){t+="["+e["code"]+"] "+e["message"]+"\r\n"}}}));var e=BX.create("textarea",{props:{className:"rest-configuration-popup-textarea",placeholder:BX.message("REST_CONFIGURATION_IMPORT_ERRORS_POPUP_TEXT_PLACEHOLDER")},html:t});var i=BX.create("div",{children:[BX.create("div",{props:{className:"rest-configuration-popup-textarea-title"},text:BX.message("REST_CONFIGURATION_IMPORT_ERRORS_POPUP_TEXT_LABEL")}),e]});var s=BX.PopupWindowManager.create("rest-configuration-popup",null,{className:"rest-configuration-popup",titleBar:BX.message("REST_CONFIGURATION_IMPORT_ERRORS_POPUP_TITLE"),content:i,contentBackground:"transparent",contentPadding:10,minWidth:250,maxWidth:450,autoHide:true,closeIcon:true,animation:"fading-slide",buttons:[new BX.UI.Button({text:BX.message("REST_CONFIGURATION_IMPORT_ERRORS_POPUP_BTN_COPY"),color:BX.UI.Button.Color.LINK,events:{click:function(){e.select();document.execCommand("copy")}}})],onPopupClose:function(){this.destroy()}});s.show()},run:function(t){if(!BX.type.isInteger(t)){this.showLoader();t=0}else{t++}this.sendAjax("run",{},BX.delegate((function(e){if(!e.data.finish){if(!!e.data.step){this.setDescription(e.data.step.toString().toUpperCase(),t)}this.run(t)}else{this.showFinish(e.data)}}),this))},start:function(){this.showLoader();this.sendAjax("start",{},BX.delegate((function(t){if(t.data.section.length>0){this.section=t.data.section;if(!!t.data.next&&t.data.next==="save"){this.loadManifest(0,"","export")}else{this.loadManifest(0,"","import")}}}),this))},finishSave:function(){this.sendAjax("finishSave",{},BX.delegate((function(t){this.loadManifest(0,"","import")}),this))},save:function(t,e){this.sendAjax("save",{code:this.section[t],step:e,next:this.next},BX.delegate((function(i){if(!!i.data){this.next=i.data.next;e++;if(this.next===false){t++;e=0}if(t>=this.section.length){this.finishSave(0,"","import")}else{this.save(t,e)}}else{this.showFatalError()}}),this))},loadManifest:function(t,e,i){this.sendAjax("loadManifest",{step:t,next:e,type:i},BX.delegate((function(e){if(!!e.data){t++;if(e.data.next===false){if(i==="export"){this.save(0,0)}else{this.clear(0,0,0)}}else{this.loadManifest(t,e.data.next,i)}}else{this.showFatalError()}}),this))},clear:function(t,e,i){if(this.skipClearing){this.import(0,0)}else{this.sendAjax("clear",{code:this.section[t],step:e,next:i},BX.delegate((function(s){e++;i=s.data.next;if(i===false){t++;e=0;i=0}if(t<this.section.length){this.clear(t,e,i)}else{this.import(0,0)}}),this))}},import:function(t,e){this.sendAjax("import",{code:this.section[t],step:e},BX.delegate((function(i){e++;if(!i.data.errors){}if(i.data.result===true){t++;e=0}if(t<this.section.length){this.import(t,e)}else{this.finish()}}),this))},showFatalError:function(t){var e="";var i=BX.findChildByClassName(BX(this.id),"rest-configuration-start-icon-main");BX.removeClass(i,"rest-configuration-start-icon-main-zip rest-configuration-start-icon-main-loading");BX.addClass(i,"rest-configuration-start-icon-main-error");if(t.length>0){for(var s=0;s<t.length;s++){if(e!==""){e+="\n"}e=t[s].message}}else if(BX.type.isString(t)){e=t}BX.cleanNode(this.progressDescriptionContainer);this.progressDescriptionContainer.appendChild(BX.create("div",{attrs:{className:"rest-configuration-fatal-error-block"},children:[],text:e!==""?e:BX.message("REST_CONFIGURATION_IMPORT_INSTALL_FATAL_ERROR")}));this.showCloseConfirmation=false},sendAjax:function(t,e,i){e.clear=this.needClearFull;BX.ajax.runComponentAction("bitrix:rest.configuration.install",t,{mode:"class",signedParameters:this.signedParameters,data:e,analyticsLabel:{from:this.from,hasErrors:this.errors.length!==0}}).then(BX.delegate((function(s){if(!!s.data.exception){this.showFatalError(s.data.exception)}else{i(s)}if(!!s.data.errors){this.addErrors(s.data.errors)}if(!!s.data["notice"]){console.log({errors:s.data["notice"],action:t,data:e,response:s})}}),this)).catch(function(t){this.showFatalError(false)}.bind(this))}};BX.Rest.Configuration.Install=new t})(window);
//# sourceMappingURL=script.map.js